package com.junzhiit.nengji.app.web.vo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import com.bainaeco.framework.base.BaseObject;

public class TreeFunctionVO extends BaseObject {

	private static final long serialVersionUID = 6164369104173516715L;

	private String id;

	private String name;

	private String icon;

	private String url;
	
	private Integer sort;

	private String parentId;

	private List<TreeFunctionVO> children = new ArrayList<TreeFunctionVO>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public List<TreeFunctionVO> getChildren() {
		return children;
	}

	public void setChildren(List<TreeFunctionVO> children) {
		this.children = children;
	}
	
	public void sortChildren() {  
		// 对本层节点进行排序  
		// 可根据不同的排序属性，传入不同的比较器，这里传入ID比较器  
		Collections.sort(this.getChildren(), new NodeIDComparator());  
		// 对每个节点的下一层节点进行排序  
		for (Iterator<TreeFunctionVO> it = children.iterator(); it.hasNext();) {  
			it.next().sortChildren();
		}  
	}
	
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}



	class NodeIDComparator implements Comparator<TreeFunctionVO> {  
		// 按照节点编号比较  
		@Override
		public int compare(TreeFunctionVO o1, TreeFunctionVO o2) {
			int j1 = o1.getSort();  
			int j2 = o2.getSort();  
			return (j1 < j2 ? -1 : (j1 == j2 ? 0 : 1)); 
		}   
	}

}
